#include<iostream>
#include<stdlib.h>
#include<assert.h>
using namespace std;
namespace zhc
{
	template<class T>
	class vector
	{
	public:
		vector()
		:_a(nullptr)
		, _capacity(0)
		, _size(0)
		{}
		~vector()
		{
			delete[] _a;
			_a = nullptr;
			_capacity = _size = 0;
		}
		void Push(const T &x)
		{
			if (_capacity == _size)
			{
				int newcapacity = _capacity == 0 ? 4 : _capacity * 2;
				T* tmp = new T[newcapacity];
				if (_a)
				{
					memcpy(tmp, _a, sizeof(T)*_size);
					delete[] _a;
				}
				_a = tmp;
				_capacity = newcapacity;
			}
			_a[_size] = x;
			++_size;
		}
		T& operator[](size_t pos)
		{
			assert(pos < _size);
			return _a[pos];
		}
		size_t size()
		{
			return _size;
		}
	private:
		T*_a;
		size_t _capacity;
		size_t _size;
	};
	/*template<class T>
	T& vector<T>::operator[](size_t pos)
	{
		assert(pos < _size);
		return _a[pos];
	}
	template<class T>
	size_t vector<T>::size()
	{
		return _size;
	}*/
}
int main()
{
	zhc::vector<int> v1;
	zhc::vector<double> v2;
	v1.Push(1);
	v1.Push(2);
	v1.Push(3);
	v1.Push(4);
	v2.Push(1.1);
	v2.Push(2.2);
	v2.Push(3.3);
	v2.Push(4.4); 
	for (size_t i = 0; i < v1.size(); i++)
	{
		v1[i] *= 2;
	}
	for (size_t i = 0; i < v1.size(); i++)
	{
		cout << v1[i] << " ";
	}
	cout << endl;
	//cout << v2[3] << endl;
	system("pause");
	return 0;
}